<template>
	<div class="main">
		<div class="list" v-if="infoList.length!=0">
			<div class="item" v-for="(order,order_index) in infoList" :key="order_index"
				 >
				<div class="title">
					<div class="orderId">订单号：{{order.order_id}}</div>
					<div class="ok">交易成功</div>
				</div>
				<div class="msg_list">
					<div class="msg_item" v-for="(goods,index) in order.info" :key="index" @click="detail(goods)">
						<div class="msg_img">
							<image :src="goods.list_pic_url"></image>
						</div>
						<!--  -->
						<div class="msg_name">{{goods.goods_name}}</div>
						<div class="msg_info">
							<div class="money">¥ {{goods.retail_price}}</div>
	                  		<div class="sum">X{{goods.number}}</div>
						</div>
					</div>
				</div>
				<div class="bottom">
					<div class="time">{{order.create_time}}</div>
					<div class="adress">
						<div class="adress_text" @click="adress(order_index)">收货地址</div>
					</div>
				</div>
				<div class="all">
					总价¥ {{order.allprice}}，实付款<span class="act">¥ {{order.allprice}}</span>
				</div>
			</div>
		</div>
		<div class="no" v-else>
			<div class="img">
				<img src="/static/images/no.png">
			</div>
			<div class="text">暂无收藏商品，快去逛逛吧~</div>
			<div class="go" @click="goIndex">去首页看好物</div>
		</div>	
	</div>
</template>
<script type="text/javascript">
import {get,post} from '@/util'
import {formatTime} from '../../utils/index.js'
export default {
	data() {
		return {
			openId:'',
			infoList:'',

		}
	},
	mounted(){
		const userinfo = wx.getStorageSync('userinfo')
		this.openId = userinfo.openId
		this.getOrderData()
	},
	methods:{
		detail(order){
			var goods_id =order.goods_id
			console.log("goods_id",goods_id)
			wx.navigateTo({
		        url: '/pages/goods/main?id=' + goods_id
		    })
		},
		async getOrderData(){
			const data = await get('/app/order/myOrder',{
				openId:this.openId,
			})
			this.infoList=[]
			for(let i=0;i<data.orderData.length;i++){
				var test ={
					order_id:data.orderData[i].order_id,
					allprice:data.orderData[i].allprice,
					address:data.orderData[i].address,
					create_time:formatTime(new Date(data.orderData[i].create_time)),
					info:data.list[i]
				}
				this.infoList.push(test)
			}
		},
		adress(order_index){
			var title=this.infoList[order_index].address
			wx.showModal({
				title:title,
				showCancel:false,
                mask:true,
                confirmText:'收起',
			})
		}
	},
}
</script>
<style lang='scss'>
	@import "./style.scss";
</style>